App.module.Language.Delete = Ext.extend(Ext.util.Observable, {
	init: function(tree){
		this.tree = tree;
		tree.on('render', function(tree){
			var bt = new Ext.Button({
				tooltip: 'Delete'
				,iconCls: 'icon-delete-16x16'
				,disabled: true
				,handler: this.del
				,scope: this
			}, this);
			
			tree.getTopToolbar().add(bt);
			
			tree.getSelectionModel().on('selectionchange', function(sm, node){
				bt.setDisabled(!node || node == tree.root);
			}, this);
			
		}, this);
	}
	,del: function(){
		var node = this.tree.getSelectionModel().getSelectedNode();
		if(!node) return;
		
		Ext.Msg.confirm('Delete', 'Do you want to delete?', function(bt){
			if('no' == bt) return;
			
			node.destroy();
			API.language.del({id: node.id});
			
		}, this);
	}
});